package springboot.houbank.com.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import springboot.houbank.com.domain.Person;
import springboot.houbank.com.domain.User;
import springboot.houbank.com.mapper.PersonMapper;
import springboot.houbank.com.mapper.UserMapper;
import springboot.houbank.com.service.UserService;

import java.util.List;

/**
 * Created by zhaoqiguo on 2016/9/8.
 */
@Transactional
@Service
public class UserServcieImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private PersonMapper personMapper;
    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED)
    public int insertUser(User user) {
        int num = userMapper.insertUser(user);
        //int n = 1/0;
        return num;
    }

    @Override
    public List<User> queryAll() {
        return userMapper.queryAll();
    }

    @Override
    public void insertData() {
        Person person = new Person();
        person.setAge(22);
        person.setName("test");
        person.setId("5");
        personMapper.insertPerson(person);

        User user = new User();
        user.setAge(22);
        user.setUsername("123");
        userMapper.insertUser(user);

    }
}
